using System;

namespace GURUCORE.Framework.Core.Data
{
    /// <summary>
    /// G: Use only with Microsoft SQL Server.
    /// Author: TrungDD
    /// Date created: 4/9/2007
    /// </summary>
    [AttributeUsage(AttributeTargets.Property)]
    public class SPPersistencePropertyAttribute : Attribute
    {
        private string m_sParamName;
        private int m_iParamOrder;
        private string m_sDirectionMode;
        private string m_sDatatype;
        private int m_iSize;
        private byte m_byPrecision;
        private byte m_byScale;

        #region CONSTRUCTOR
        public SPPersistencePropertyAttribute()
        {
        }

        public SPPersistencePropertyAttribute(string p_sParamName, int p_iParamOrder, string p_sDirectionMode, string p_sDataType, int p_iSize, byte p_byPrecision, byte p_byScale)
        {
            m_sParamName = p_sParamName;
            m_iParamOrder = p_iParamOrder;
            m_sDirectionMode = p_sDirectionMode;
            m_sDatatype = p_sDataType;
            m_iSize = p_iSize;
            m_byPrecision = p_byPrecision;
            m_byScale = p_byScale;
        }

        #endregion
        #region PROPERTIES
        public string ParamName
        {
            get
            {
                return m_sParamName;
            }
        }
        public int ParamOrder
        {
            get
            {
                return m_iParamOrder;
            }
        }
        public string DirectionMode
        {
            get
            {
                return m_sDirectionMode;
            }
        }
        public int Size
        {
            get
            {
                return m_iSize;
            }
        }
        public byte Precision
        {
            get
            {
                return m_byPrecision;
            }
        }
        public byte Scale
        {
            get
            {
                return m_byScale;
            }
        }
        public System.Data.SqlDbType DbType
        {
            get
            {
                //TrungDD: 1/9/2007 FIX for SQL SERVER 2000.
                if (m_sDatatype.Equals("bigint")) return System.Data.SqlDbType.BigInt;
                else if (m_sDatatype.Equals("binary")) return System.Data.SqlDbType.Binary;
                else if (m_sDatatype.Equals("bit")) return System.Data.SqlDbType.Bit;
                else if (m_sDatatype.Equals("char")) return System.Data.SqlDbType.Char;
                else if (m_sDatatype.Equals("datetime")) return System.Data.SqlDbType.DateTime;
                else if (m_sDatatype.Equals("decimal")) return System.Data.SqlDbType.Decimal;
                else if (m_sDatatype.Equals("float")) return System.Data.SqlDbType.Float;
                else if (m_sDatatype.Equals("int")) return System.Data.SqlDbType.Int;
                else if (m_sDatatype.Equals("money")) return System.Data.SqlDbType.Money;
                else if (m_sDatatype.Equals("nchar")) return System.Data.SqlDbType.NChar;
                else if (m_sDatatype.Equals("ntext")) return System.Data.SqlDbType.NText;
                else if (m_sDatatype.Equals("nvarchar")) return System.Data.SqlDbType.NVarChar;
                else if (m_sDatatype.Equals("real")) return System.Data.SqlDbType.Real;
                else if (m_sDatatype.Equals("smalldatetime")) return System.Data.SqlDbType.SmallDateTime;
                else if (m_sDatatype.Equals("smallint")) return System.Data.SqlDbType.SmallInt;
                else if (m_sDatatype.Equals("smallmoney")) return System.Data.SqlDbType.SmallMoney;
                else if (m_sDatatype.Equals("timestamp")) return System.Data.SqlDbType.Timestamp;
                else if (m_sDatatype.Equals("tinyint")) return System.Data.SqlDbType.TinyInt;
                else if (m_sDatatype.Equals("uniqueidentifier")) return System.Data.SqlDbType.UniqueIdentifier;
                else if (m_sDatatype.Equals("varbinary")) return System.Data.SqlDbType.VarBinary;
                else if (m_sDatatype.Equals("varchar")) return System.Data.SqlDbType.VarChar;
                else if (m_sDatatype.Equals("sql_variant")) return System.Data.SqlDbType.Variant;
                else return System.Data.SqlDbType.NVarChar;
            }
        }
        public System.Data.ParameterDirection DirectionType
        {
            get
            {
                //TrungDD: 31/8/2007 FIX for SQL SERVER 2000.
                if (m_sDirectionMode.Equals("INOUT")) return System.Data.ParameterDirection.InputOutput;
                else if (m_sDirectionMode.Equals("IN")) return System.Data.ParameterDirection.Input;
                else if (m_sDirectionMode.Equals("OUT")) return System.Data.ParameterDirection.Output;
                return System.Data.ParameterDirection.Input;
            }
        }
        #endregion
    }
}
